import itertools
import os
from pathlib import Path

import pytest

from storage.blobstore.crypto import EncryptionAlgorithm
from storage.encryption import encrypt_file, decrypt_file


@pytest.mark.parametrize('block_size,algo,parallel', itertools.product(
    [2 ** i for i in range(13, 17)],
    EncryptionAlgorithm.__members__.values(),
    range(1, 8),
))
def test_encryption(input_path: Path, output_path: Path, block_size: int, algo: EncryptionAlgorithm, parallel):
    key = os.urandom(algo.key_size)
    encrypt_file(input_path, output_path / (input_path.name + '.enc'), block_size, algo, key)
    decrypt_file(output_path / (input_path.name + '.enc'), output_path / input_path.name, key)
    assert input_path.read_bytes() == (output_path / input_path.name).read_bytes()
